<template>
  <div class="news-detail">
    <myheader outerTitle="新闻列表"></myheader>
    <div class="news-list">
      <ul>
        <li v-for="item in newsLists" :key="item.id" @click="jumpToDetail(item.id)">
          <div class="news-item">
            <img :src="item.img_url" :alt="item.title">
            <div class="content">
              <p class="content-title">{{item.title}}</p>
              <p class="content-info">
                <span class="content-time">{{item.add_time | filterTime}}</span>
                <span class="content-click">{{item.click}}</span>
              </p>
            </div>
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import myheader from '@/components/myheader.vue'
import { getNewsList } from '@/api'
export default {
  components: {
    myheader
  },
  created () {
    this.initList()
  },
  data () {
    return {
      newsLists: []
    }
  },
  methods: {
    initList () {
      getNewsList()
        .then(res => {
          // console.log(res)
          this.newsLists = res.message
        })
    },
    jumpToDetail (id) {
      // console.log(id)
      // this.$router.push('newsdetail/' + id)
      this.$router.push({ name: 'newsdetail', params: { id } })
    }
  }

}
</script>

<style lang="scss">
  .news-list {
    ul {
      padding: 40px 0 0 0;
      li {
        padding: 5px;
      }
    }
    .news-item {
      display: flex;
      justify-content: space-between;
      align-items: center;
      img {
        width: 100px;
        height: 50px;
        margin-right: 10px;
        flex: 1;
      }
      .content {
        flex: 2;
        width: 250px;
        .content-title {
          font-size: 14px;
          font-weight: bold;
        }
        .content-info {
          display: flex;
          justify-content: space-between;
          color: #26a2ff;
          font-size: 12px;
        }
      }
    }
  }
</style>
